<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" id="vp" content="width=device-width, initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <link href="../css/login_reg.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="../css/animate.css">
    <title>登陆</title>
    <style>
        * {
            margin: 0;
        }
        html{
        	height: 100%;
        }
        body{
				background:#EEF6FF!important;
				min-height: 100%;
			}
			body,


    </style>
</head>

<body class="bg_f">
    <div id="login" style="height: 100%; position:fixed; width: 100%;">
        <div class="logreg">
            <img class="loginLeft animated fadeInDown" src="../images/loginleft.png" alt="">
            <img class="loginright animated fadeInUp" src="../images/loginright.png" alt="">
            <img src="../images/newlogo.png" class="logreg-banner logreg-wrap animated fadeInDown" />
            <div class="logreg-input-frame logreg-wrap">
                <!-- <form action=""> -->
                <input type="" name="accountTxt" id="accountTxt" value="" style="font-size: 14px;" placeholder="账号" class="logreg-input animated fadeInUp" />
                <input type="password" name="passwordTxt" id="passwordTxt" value="" style="font-size: 14px;" placeholder="密码" class="logreg-input animated fadeInUp" />
                <div class="login-a-frame clearfix">
                    <a id="regBtn" href="reg.html" class="login-reg fl" style="color:#888888;">注册新用户</a>
                    <a id="fpwdBtn" href="findpwd.html" class="login-password fr" style="color:#888888;">忘记密码</a>
                </div>
                <button type="button" name="loginBtn" id="loginBtn" class="logreg-input buttom animated fadeInUp" />登录</button>
                <!-- </form> -->
            </div>
            <!-- <div class="logreg-line">Copyright © 2018 All Rights Reserved</div> -->
        </div>
    </div>
	<script src="../js/token.js"></script>
    <script src="../js/mui.js"></script>
    <script src="../js/app.js"></script>
    <script src="../js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" charset="UTF-8">
        mui.init();

        mui.plusReady(function() {
        	
            //锁定屏幕方向，防止变形
            var wv = plus.webview.currentWebview();
            // 关闭侧滑返回功能  
            wv.setStyle({
                'popGesture': 'none'
            });
            plus.screen.lockOrientation("portrait-primary");
            //跳转至首页
            var toMain = function() {
            	state = app.getState();
                type = state.type;
                if(type==1){
                	mui.openWindow({
	                    url: 'ScanQRcode.html',
	                    id: 'ScanQRcode',
	                    preload: true, 
	                    show: {
	                        aniShow: 'pop-in'
	                    },
	                    styles: {
	                        popGesture: 'hide'
	                    },
	                    waiting: {
	                        autoShow: false
	                    }
                	});
                }else{
                	mui.openWindow({
	                    url: 'main.html',
	                    id: 'main',
	                    preload: true, 
	                    show: {
	                        aniShow: 'pop-in'
	                    },
	                    styles: {
	                        popGesture: 'hide'
	                    },
	                    waiting: {
	                        autoShow: false
	                    }
                	});
                }
                
            };

            //检查 "登录状态状态"
            var settings = app.getSettings();
            var state = app.getState();
            var memeberToken = state.memberToken;
           
                //console.log(state.userid);
           /* if (state.userid) {
                toMain();
            }*/
            // 关闭登陆展示页
            setTimeout(function() {
                plus.navigator.closeSplashscreen();
            }, 600);

            var loginBtn = document.getElementById('loginBtn');
            var accountTxt = document.getElementById('accountTxt');
            var passwordTxt = document.getElementById('passwordTxt');
            var regBtn = document.getElementById('regBtn');
            var forgetBtn = document.getElementById('fpBtn');

            document.getElementById("loginBtn").addEventListener("keypress", function(event) {
                if (event.keyCode == "13") {
                    document.activeElement.blur(); //收起虚拟键盘
                    // toSearch(); //TODO 完成搜索事件
                    var loginInfo = {
                        tel: accountTxt.value,
                        pwd: passwordTxt.value
                    };
                    app.login(loginInfo, function(err) {
                        if (err) {
                            plus.nativeUI.toast(err);
                            return;
                        }
                        
                        toMain();
                    });
                    event.preventDefault(); // 阻止默认事件---阻止页面刷新
                }
            });
            loginBtn.addEventListener('tap', function(event) {
                var loginInfo = {
                    tel: accountTxt.value,
                    pwd: passwordTxt.value
                };
                app.login(loginInfo, function(err) {
                	
                    if (err) {
                        plus.nativeUI.toast(err);
                        return;
                    }
                    toMain();
                });
            });
            regBtn.addEventListener('tap', function(event) {
                mui.openWindow({
                    url: 'reg.html',
                    id: 'reg',
                    preload: true,
                    show: {
                        aniShow: 'pop-in'
                    },
                    styles: {
                        popGesture: 'hide'
                    },
                    waiting: {
                        autoShow: false
                    }
                });
            }, false);
            fpwdBtn.addEventListener('tap', function(event) {
                mui.openWindow({
                    url: 'findpwd.html',
                    id: 'findpwd',
                    preload: true,
                    show: {
                        aniShow: 'pop-in'
                    },
                    styles: {
                        popGesture: 'hide'
                    },
                    waiting: {
                        autoShow: false
                    }
                });
            }, false);
            var backButtonPress = 0;
            mui.back = function(event) {
                backButtonPress++;
                if (backButtonPress > 1) {
                    plus.runtime.quit();
                } else {
                    plus.nativeUI.toast('再按一次退出应用');
                }
                setTimeout(function() {
                    backButtonPress = 0;
                }, 1000);
                return false;
            };
        });
    </script>
</body>

</html>